package br.inf.solutions.apresentacoes.ssp.model.bulletin.items;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import br.com.vexillum.model.annotations.SearchField;
import br.com.vexillum.model.annotations.Validate;
import br.com.vexillum.model.annotations.ValidatorClass;
import br.com.vexillum.util.SpringFactory;
import br.inf.solutions.apresentacoes.ssp.control.PromotionController;
import br.inf.solutions.apresentacoes.ssp.model.Person;
import br.inf.solutions.apresentacoes.ssp.model.SquarePostGraduation;
import br.inf.solutions.apresentacoes.ssp.model.basics.CriterionPromotion;
import br.inf.solutions.apresentacoes.ssp.model.bulletin.BulletinItem;
import br.inf.solutions.apresentacoes.ssp.model.bulletin.BulletinTopics;
import br.inf.solutions.apresentacoes.ssp.model.interfaces.IExistsPerson;

@SuppressWarnings("serial")
@ValidatorClass(validatorClass = "br.inf.solutions.apresentacoes.ssp.control.validator.PromotionValidator")
@Entity
@Table(name = "promotion")
public class Promotion extends BulletinItem implements IExistsPerson{

	@SearchField
	@Validate(notNull = true)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_person", nullable = true, updatable = true, unique = false)
	private Person person;

	@Validate(notNull = true)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_squarePostGraduation", nullable = false, updatable = true, unique = false)
	private SquarePostGraduation squarePostGraduation;

	@Validate(notNull = true)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_criterion", nullable = false, updatable = true, unique = false)
	private CriterionPromotion criterion;

	@Validate(notNull = true)
	@Column(name = "promotion_date", nullable = false, updatable = true, unique = false)
	private Date promotionDate;
	
	public Promotion() {
		super(new BulletinTopics(2l, "Promotion", "/paginas/promocao/retificacao.zul"));
	}

	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	public SquarePostGraduation getSquarePostGraduation() {
		return squarePostGraduation;
	}

	public void setSquarePostGraduation(
			SquarePostGraduation squarePostGraduation) {
		this.squarePostGraduation = squarePostGraduation;
	}

	public CriterionPromotion getCriterion() {
		return criterion;
	}

	public void setCriterion(CriterionPromotion criterion) {
		this.criterion = criterion;
	}

	public Date getPromotionDate() {
		return promotionDate;
	}

	public void setPromotionDate(Date promotionDate) {
		this.promotionDate = promotionDate;
	}

	@Override
	public PromotionController getControl() {
		return SpringFactory.getController("promotionController", PromotionController.class, null);
	}

}
